package ppjava12v1.chess.service;

import org.springframework.stereotype.Service;
import ppjava12v1.chess.desk.Desk;
import ppjava12v1.chess.desk.Figure;
import ppjava12v1.chess.entities.games.Game;
import ppjava12v1.chess.enums.FigureType;
import ppjava12v1.chess.enums.Side;

/**
 * Created by Reyst on 05.10.2014.
 */
@Service
public class GameService {
    
    public void startGame(Game game){
        prepareDesk(game.getDesk());
    }

    private void prepareDesk(Desk desk) {
        
        // Первоначальная расстановка фигур
        
        // Белые
        Side side = Side.WHITE;
        for (int i = 1; i < 9; i++)
            desk.putFigureTo(2, i, new Figure(side, FigureType.PAWN));
        
        desk.putFigureTo(1, 1, new Figure(side, FigureType.ROOK));
        desk.putFigureTo(1, 8, new Figure(side, FigureType.ROOK));

        desk.putFigureTo(1, 2, new Figure(side, FigureType.KNIGHT));
        desk.putFigureTo(1, 7, new Figure(side, FigureType.KNIGHT));

        desk.putFigureTo(1, 3, new Figure(side, FigureType.BISHOP));
        desk.putFigureTo(1, 6, new Figure(side, FigureType.BISHOP));

        desk.putFigureTo(1, 4, new Figure(side, FigureType.QUEEN));
        desk.putFigureTo(1, 5, new Figure(side, FigureType.KING));


        // Черные
        side = Side.BLACK;
        for (int i = 1; i < 9; i++)
            desk.putFigureTo(7, i, new Figure(side, FigureType.PAWN));

        desk.putFigureTo(8, 1, new Figure(side, FigureType.ROOK));
        desk.putFigureTo(8, 8, new Figure(side, FigureType.ROOK));

        desk.putFigureTo(8, 2, new Figure(side, FigureType.KNIGHT));
        desk.putFigureTo(8, 7, new Figure(side, FigureType.KNIGHT));

        desk.putFigureTo(8, 3, new Figure(side, FigureType.BISHOP));
        desk.putFigureTo(8, 6, new Figure(side, FigureType.BISHOP));

        desk.putFigureTo(8, 4, new Figure(side, FigureType.QUEEN));
        desk.putFigureTo(8, 5, new Figure(side, FigureType.KING));
        
    }


}
